home *** CD-ROM | disk | FTP | other *** search
- { sound_demo - A simple Personal Pascal sound demo program.
-
- You must turn off key-clicks using the control panel before running this
- program, as the key-click routine in the OS will mess up your sound! We
- hope soon to add to this demo an XBIOS call to turn off the keyclicks. }
-
- PROGRAM sound_demo ;
-
- CONST
- cmd_write = 128 ;
- cmd_read = 0 ;
- chana_lo = 0 ;
- chana_hi = 1 ;
- chana_vol = 8 ;
- chan_enable = 7 ;
- enable_sound = 7 ;
-
- TYPE
- channel = 0..2 ;
-
- VAR
- volume, note : integer ;
-
-
-
- { Two XBIOS functions (actually one call with two definitions!) needed to
- access the General Instruments sound chip. }
-
- FUNCTION gia_read( data, register : integer ) : integer ;
- XBIOS( 28 ) ;
-
- PROCEDURE gia_write( data, register : integer ) ;
- XBIOS( 28 ) ;
-
-
-
- { Call this routine to enable sound to be generated. }
-
- PROCEDURE Sound_Init ;
-
- VAR
- port_state : integer ;
-
- BEGIN
- port_state := gia_read( 0, chan_enable+cmd_read ) ;
- gia_write( port_state&(~enable_sound), chan_enable+cmd_write ) ;
- END ;
-
-
-
- { This routine turns on a particular note on one of the three channels. }
-
- PROCEDURE Sound( ch : channel ; pitch : integer ; vol : integer ) ;
-
- BEGIN
- gia_write( vol, chana_vol+ch+cmd_write ) ;
- gia_write( pitch&$FF, chana_lo+ch*2+cmd_write ) ;
- gia_write( shr(pitch,8), chana_hi+ch*2+cmd_write ) ;
- END ;
-
-
-
- { Call this routine to turn off sound after you're finished. }
-
- PROCEDURE Sound_Off ;
-
- VAR
- port_state : integer ;
-
- BEGIN
- Sound( 0, 0, 0 ) ; { First, make sure all volumes are zero. }
- Sound( 1, 0, 0 ) ;
- Sound( 2, 0, 0 ) ;
- { Now disable sound production on all three channels. }
- port_state := gia_read( 0, chan_enable+cmd_read ) ;
- gia_write( port_state|enable_sound, chan_enable+cmd_write ) ;
- END ;
-
-
- BEGIN
- { Main program loop-- ask user for a volume to use... should be 0-15. }
- LOOP
- write( 'volume: ' ) ;
- readln( volume ) ;
-
- EXIT IF volume = 0 ;
-
- sound_init ; { Enable sound. }
-
- { Sub-loop-- keep generating notes until user enters 0 as a pitch. }
- LOOP
- write( 'note: ' ) ;
- readln( note ) ;
- EXIT IF note = 0 ;
- sound( 0, note, volume ) ;
- END ;
-
- sound_off ; { Disable the sound. }
- END ;
- END.
-
- 33333333333333333333333333333333333333333333333333333333333333333333333333333